import { project } from '@/constances';

export const state = {
    frameworks: [
        {
            label: 'wepy',
            id: 'wepy',
            checked: false
        },
        {
            label: 'mpvue',
            id: 'mpvue',
            checked: false
        },
        {
            label: '原生小程序',
            checked: false
        }        
    ]
};

export const getters = {
    frameworks: state => state.frameworks,
    selectedFramework: state => state.frameworks.filter(({ selected }) => selected)[0]
};

export const actions = {
    select({ commit }, framework) {
        commit(project.SELECT_FRAMEWORK, framework);
    }
};

export const mutations = {
    [project.SELECT_FRAMEWORK](state, framework) {
        state.frameworks = state.frameworks.map((item) => {
            item.selected = false;
            if (item.id === framework.id) {
                item.selected = true;
            }
            return item;
        });
    }
};
